package cn.wolfcode.wolfcodemall.controller.admin;

import cn.wolfcode.wolfcodemall.domain.ProductOrder;
import cn.wolfcode.wolfcodemall.service.OrderService;
import lombok.Data;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.*;

@Controller
@RequestMapping("/admin")
public class OrderAdminController {
    @Autowired
    private OrderService orderService;
    @RequestMapping("/order")
    public String order(Model model,
                        @RequestParam( value = "productOrderCode", required = false) Integer productOrderCode,
                        @RequestParam(value = "productOrderPost", required = false) Integer productOrderPost,
                        @RequestParam(value = "productOrderStatus",required = false) List<Integer> productOrderStatus){
        Map<String, Object> pageResult = new HashMap<>();

        List<ProductOrder> list = orderService.selectAll(productOrderCode,productOrderPost, productOrderStatus);
        int total = list.toArray().length;
        pageResult.put("list", list);
        pageResult.put("total", total);

        model.addAttribute("pageResult", pageResult);
        return "/admin/orderManagePage";
    }

    @RequestMapping("/orderDetails/{orderItemId}")
    public String selectById(@PathVariable("orderItemId") Integer orderId, Model model){
        System.out.println(orderId);
        ProductOrder order = orderService.selectById(orderId);
        model.addAttribute("order",order);
        System.out.println(order);
        return "/admin/orderDetails";
    }

    /**
     * 发货
     */
    @RequestMapping("/orderDetails/admin/order/{orderId}")
    public String sendOrder(@PathVariable("orderId") Integer orderId) {
        orderService.logicDeleteByOrderId(orderId, 2);

        return "/admin/orderDetails";
    }
}